#include <fstream>
#include <iostream>

#include "CHttpClient.hpp"
#include "json.h"

using namespace std;

int main(int argc, char **argv) {
    // 同步网络
//    CHttpClient net;

    string htmlStr = "";
    string response;
    CHttpClient::getInstance()->Post("http://101.132.115.120:8000/calmcar/activateDevice?device_id=861130040739701", htmlStr, response);

    cout << response << endl;

    Json::Value root;
    Json::Reader jsonReader;
    if (!jsonReader.parse(response, root)) {
        cout << "parse json error!" << endl;
        return -1;
    }
    cout << "Json Object result \n\n";
    if (root["error_code"].asInt() == 0) {
        cout << "code: " << root["error_code"].asInt() << std::endl;
        cout << "msg: " << root["error_msg"].asString() << std::endl;
        cout << "activate_code: " << root["activate_code"].asString() << std::endl;
    } else {
        cout << "code: " << root["error_code"].asInt() << std::endl;
        cout << "msg: " << root["error_msg"].asString() << std::endl;
    }

    return 0;
}
